package router

import (
	"github.com/gin-gonic/gin"
	"github.com/swaggo/files"
	"github.com/swaggo/gin-swagger"
	"zhou_gin_api/app/handler"
	"zhou_gin_api/app/handler/user"
	"zhou_gin_api/config"
	"zhou_gin_api/docs"
)

func InitRouter(middlewares ...gin.HandlerFunc) *gin.Engine {

	swaggerConfig := config.GetSwaggerConfig()

	docs.SwaggerInfo.Title = swaggerConfig.Title
	docs.SwaggerInfo.Description = swaggerConfig.Desc
	docs.SwaggerInfo.Version = "1.0"
	docs.SwaggerInfo.Host = swaggerConfig.Host
	docs.SwaggerInfo.BasePath = swaggerConfig.BasePath
	docs.SwaggerInfo.Schemes = []string{"http", "https"}

	router := gin.Default()
	router.Use(middlewares...)

	router.GET("/hello", handler.Hello)

	userRouter := router.Group("/user")
	{
		userRouter.GET("/", user.Index)
		userRouter.GET("/:id", user.Show)
		userRouter.POST("/", user.Add)
		userRouter.PUT("/:id", user.Update)
		userRouter.DELETE("/:id", user.Delete)
	}

	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	return router

}
